package com.xuetang9.fujian.threaddemo.threadpooldemo;

import java.util.concurrent.TimeUnit;

/**
 * @author: fujian
 * @description: 实现自定义线程池，是生产者与消费者的实现
 * @date: 2021/5/9 9:28
 * @version: V1.0
 * @package: com.xuetang9.fujian.threaddemo.threadpooldemo
 **/
@SuppressWarnings("all")
public class AppMain {
    public static void main(String[] args) {
        ThreadPool threadPool = new ThreadPool("5");
        for (int i = 0; i < 10; i++) {
            threadPool.runTask(CreatTask(i + 1));
        }
        threadPool.join();
    }

    private static Runnable CreatTask(int taskId){
        return new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName() + "开始执行任务：" + taskId);
                try {
                    TimeUnit.MILLISECONDS.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "执行任务结束：" + taskId);

            }
        };
    }
}
